<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>mysqlCookBook01 | 静待花开</title><meta name="author" content="brad 随风起舞"><meta name="copyright" content="brad 随风起舞"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="设置mysql用户账户假设已经完成了msql的安装.这里我们使用命令行在windows上来设置:  用系统root用户登陆mysql服务的命令语句如下:  mysql -h localhost -u root -p Enter password: ****** 或者: mysql –host&#x3D;localhost –user&#x3D;root –password&#x3D;pass 一般">
<meta property="og:type" content="article">
<meta property="og:title" content="mysqlCookBook01">
<meta property="og:url" content="https://zhangbo4881820.gitee.io/myblog/posts/15095/index.html">
<meta property="og:site_name" content="静待花开">
<meta property="og:description" content="设置mysql用户账户假设已经完成了msql的安装.这里我们使用命令行在windows上来设置:  用系统root用户登陆mysql服务的命令语句如下:  mysql -h localhost -u root -p Enter password: ****** 或者: mysql –host&#x3D;localhost –user&#x3D;root –password&#x3D;pass 一般">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png">
<meta property="article:published_time" content="2019-11-25T09:02:53.000Z">
<meta property="article:modified_time" content="2023-09-07T09:44:01.898Z">
<meta property="article:author" content="brad 随风起舞">
<meta property="article:tag" content="mysql">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png"><link rel="shortcut icon" href="/myblog/img/favicon.png"><link rel="canonical" href="https://zhangbo4881820.gitee.io/myblog/posts/15095/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/myblog/css/index.css"><link rel="stylesheet" href="/myblog/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="/myblog/css/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/myblog/',
  algolia: undefined,
  localSearch: {"path":"/myblog/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'mysqlCookBook01',
  isPost: true,
  isHome: false,
  isHighlightShrink: true,
  isToc: true,
  postUpdate: '2023-09-07 17:44:01'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 7.0.0-rc2"><link rel="alternate" href="/myblog/atom.xml" title="静待花开" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/myblog/archives/"><div class="headline">文章</div><div class="length-num">57</div></a><a href="/myblog/tags/"><div class="headline">标签</div><div class="length-num">20</div></a><a href="/myblog/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myblog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 分享</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/myblog/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/myblog/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/myblog/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/myblog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/myblog/" title="静待花开"><span class="site-name">静待花开</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myblog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 分享</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/myblog/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/myblog/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/myblog/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/myblog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">mysqlCookBook01</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-11-25T09:02:53.000Z" title="发表于 2019-11-25 17:02:53">2019-11-25</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-09-07T09:44:01.898Z" title="更新于 2023-09-07 17:44:01">2023-09-07</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/myblog/categories/mysql/">mysql</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="mysqlCookBook01"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><h1 id="设置mysql用户账户"><a href="#设置mysql用户账户" class="headerlink" title="设置mysql用户账户"></a>设置mysql用户账户</h1><p>假设已经完成了msql的安装.这里我们使用命令行在windows上来设置:</p>
<ol>
<li><p>用系统root用户登陆mysql服务的命令语句如下:</p>
<blockquote>
<p>mysql -h localhost -u root -p<br> Enter password: ******<br> 或者:<br> mysql –host&#x3D;localhost –user&#x3D;root –password&#x3D;pass<br> 一般默认host就是localhost 因此,如果是localhost,host可以不用写<br> mysql -u root -p</p>
</blockquote>
</li>
<li><p>然后创建一个用户</p>
<blockquote>
<p>CREATE USER ‘cbuser‘@’localhost’ IDENTIFIED BY ‘cbpass’;<br> Query OK, 0 rows affected (0.01 sec)</p>
</blockquote>
</li>
<li><p>给用户分配权限</p>
<blockquote>
<p>GRANT ALL ON cookbook.* TO ‘cbuser‘@’localhost’;<br> Query OK, 0 rows affected (0.01 sec)</p>
</blockquote>
</li>
<li><p>退出MySQL</p>
<blockquote>
<p>quit</p>
</blockquote>
</li>
</ol>
<h1 id="创建数据库和数据表"><a href="#创建数据库和数据表" class="headerlink" title="创建数据库和数据表"></a>创建数据库和数据表</h1><ol>
<li><p>建数据库</p>
<blockquote>
<p>create database cookbook</p>
</blockquote>
</li>
<li><p>使用数据库</p>
<blockquote>
<p>use cookbook</p>
</blockquote>
</li>
<li><p>建表</p>
<blockquote>
<p>create table limbs (thing varchar(20),legs INT,arms INT);</p>
</blockquote>
</li>
<li><p>插入数据</p>
<blockquote>
<p>insert into limbs (thing,legs,arms) values(‘human’,2,2);<br> insert into limbs (thing,legs,arms) values(‘insect’,6,0);<br> insert into limbs (thing,legs,arms) values(‘squid’,0,10);</p>
</blockquote>
</li>
<li><p>查询表</p>
<blockquote>
<p>select * from limbs</p>
</blockquote>
</li>
</ol>
<h1 id="其他mysql程序"><a href="#其他mysql程序" class="headerlink" title="其他mysql程序"></a>其他mysql程序</h1><ul>
<li><strong>mysqldump</strong><br>例如:生成一份cookbook.sql转储文件.执行语句如下:<blockquote>
<p>mysqldump -u cbuser -p cookbook &gt; cookbook.sql<br>  Enter password: cbpass</p>
</blockquote>
</li>
<li><strong>mysqladmin</strong><br>对于MySQL账户的管理,这个程序只对root账户执行操作,例如关闭mysql的服务:<blockquote>
<p>mysqladmin -h localhost -u root -p shutdown<br>  Enter password:输入root用户密码</p>
</blockquote>
</li>
</ul>
<h1 id="各种MySQL程序组"><a href="#各种MySQL程序组" class="headerlink" title="各种MySQL程序组"></a>各种MySQL程序组</h1><ul>
<li><strong>[mysqld]:</strong> 这个可选组用来设置服务的sql-mode系统变量的.</li>
</ul>
<h1 id="各种命令语句"><a href="#各种命令语句" class="headerlink" title="各种命令语句"></a>各种命令语句</h1><ul>
<li><p>要找出mysql程序将从选项文件中读取哪些选项;请使用以下命令:</p>
<blockquote>
<p>mysql –print-defaults<br>  或者找出指定客户组的<br>  my_print_defaults client mysqldump</p>
</blockquote>
</li>
<li><p>查找当前时间</p>
<blockquote>
<p>select now();<br>  #这是垂直展示行的命令\G<br>  select now()\G</p>
</blockquote>
</li>
<li><p>直接在命令行执行查询</p>
<blockquote>
<p>mysql -e “select count(*) from limbs” cookbook -ucbuser -p<br>  以HTML格式输出 符号&gt;后面就是输出文件<br>  mysql -H -e “select count(*) from limbs” cookbook -ucbuser -p &gt; limbs.html<br>  以XML格式输出可以加-X<br>  mysql -X -e “select count(*) from limbs” cookbook -ucbuser -p &gt; limbs.xml<br>  或者执行多条语句:<br>  mysql -e “SELECT COUNT(*) FROM limbs;SELECT NOW()” cookbook -ucbuser -p<br>  让输出值只包含数据值没有头行那些–skip-column-names<br>  mysql –skip-column-names  -e “select arms from limbs” cookbook -ucbuser -p<br>  或者<br>  mysql -ss  -e “select arms from limbs” cookbook -ucbuser -p</p>
</blockquote>
</li>
<li><p>执行脚本文件</p>
<blockquote>
<p>mysql cookbook &gt; cookbook.sql -ucbuser -p</p>
</blockquote>
</li>
</ul>
<p>	</p>
<h2 id="用户自定义变量"><a href="#用户自定义变量" class="headerlink" title="用户自定义变量"></a><strong>用户自定义变量</strong></h2><p>保存一个通过一个select语句返回的值,把这个值签入用户定义的变量里.接下来会允许你在其他语句中引用这个变量.如下语句</p>
<pre><code>SELECT @max_limbs := MAX(arms+legs) FROM limbs;
//接着可以应用@max_limbs变量了
SELECT * FROM limbs WHERE arms+legs = @max_limbs;
</code></pre>
<p>另外一种使用方式是用来记录最后插入的ID值</p>
<pre><code>SELECT @last_id := LAST_INSERT_ID();
</code></pre>
<p>用户自定义变量只能支持单个值,如果select返回多个值,那么用户变量存储最后一行的值如下.</p>
<pre><code>SELECT @name := thing FROM limbs WHERE legs = 0
结果:
squid
fish
phonograph
select @name
结果:
phonograph
</code></pre>
<p>可以使用<strong>SET</strong>来明确指定一个值作为用户变量.使用:&#x3D;或者&#x3D;都可以</p>
<pre><code>    SET @sum = 4 + 7;
    SELECT @sum;
    结果:
    11
    //也可以用子查询结果赋给变量
    SET @max_limbs = (SELECT MAX(arms+legs) FROM limbs);
</code></pre>
<p>变量名字是不区分大小写的.<br>用户变量只能出现在允许使用表达式的地方，而不能出现在必须提供常量或文字标识符的地方。<br>SET也被用于分配值给存储过程的参数和本地变量,系统变量.</p>
<h2 id="时间格式化函数DATE-FORMAT-date-format"><a href="#时间格式化函数DATE-FORMAT-date-format" class="headerlink" title="时间格式化函数DATE_FORMAT(date,format)"></a>时间格式化函数DATE_FORMAT(date,format)</h2><pre><code>    SELECT DATE_FORMAT(t,&#39;%Y-%m-%d&#39;),CONCAT(srcuser,&#39;@&#39;,srchost),size from mail
    结果:
    2019-11-26	barb@saturn	58274
    2019-11-26	tricia@mars	194925
    查找单个的年月日小时分秒.distinct去重
    SELECT DISTINCT YEAR(t),MONTH(t),DAYOFMONTH(t),HOUR(t),MINUTE(t),SECOND(t) FROM mail;
</code></pre>
<h2 id="空表达式"><a href="#空表达式" class="headerlink" title="空表达式"></a>空表达式</h2><p>使用适当的比较操作:<strong>IS NULL,IS NOT NULL,OR &lt;&#x3D;&gt;</strong></p>
<p><strong>IF()和IFNULL():</strong></p>
<pre><code>SELECT IF(legs is null,&#39;unknow&#39;,legs),IFNULL(arms,&#39;unknow&#39;) from limbs; 
SELECT IFNULL(legs,&#39;unknow&#39;),IFNULL(arms,&#39;unknow&#39;) from limbs; 
</code></pre>
<p>这两条语句一个意思,就是如果legs和arms字段为空那么用’unknow’填充.对于空比较,第二个语句更高效.</p>
<h2 id="使用视图"><a href="#使用视图" class="headerlink" title="使用视图"></a>使用视图</h2><p>假如你经常要用到如下查询:</p>
<pre><code>SELECT
DATE_FORMAT( t, &#39;%Y-%m-%d&#39; ) AS date_sent,
CONCAT( srcuser, &#39;@&#39;, srchost ) AS sender,
CONCAT( dstuser, &#39;@&#39;, dsthost ) AS recipient,
size 
FROM
mail;
</code></pre>
<p>可以看到这条语句很长,经常使用的话写起来麻烦,那么可以用视图来解决.视图是一个虚拟表,它不包含任何数据.下面基于上面查询建立视图:</p>
<pre><code>CREATE VIEW mail_view AS SELECT
DATE_FORMAT( t, &#39;%Y-%m-%d&#39; ) AS date_sent,
CONCAT( srcuser, &#39;@&#39;, srchost ) AS sender,
CONCAT( dstuser, &#39;@&#39;, dsthost ) AS recipient,
size 
FROM
mail;
</code></pre>
<p>现在就可以直接从视图中取得需要的结果,使用视图和使用表一样,如下:</p>
<pre><code>SELECT date_sent,sender,size from mail_view where size &gt; 100000 ORDER BY size;
</code></pre>
<h2 id="多个表中查询数据"><a href="#多个表中查询数据" class="headerlink" title="多个表中查询数据"></a>多个表中查询数据</h2><p>可以使用<strong>join</strong>或者<strong>子查询</strong>来实现多表联合查.</p>
<pre><code>SELECT
id,
NAME,
service,
contact_name
FROM
PROFILE INNER JOIN profile_contact ON id = profile_id;
</code></pre>
<p>FROM指出从哪些表中取数据,并且<strong>ON</strong>条件告诉mysql使用哪些列去查找表之间的匹配项.在这个例子中,id和NAME来自PROFILE表,service和contact_name来自profile_contact表.接下来使用子查询,如下:</p>
<pre><code>SELECT
* 
FROM
profile_contact 
WHERE
profile_id = ( SELECT id FROM PROFILE WHERE NAME = &#39;Nancy&#39; );
</code></pre>
<h2 id="LIMIT使用"><a href="#LIMIT使用" class="headerlink" title="LIMIT使用"></a>LIMIT使用</h2><p>当一个参数的时候就是限定展示多少行数据.</p>
<pre><code>SELECT * FROM profile ORDER BY birth DESC LIMIT 1;
</code></pre>
<p>这里就是展示birth降序排列的结果的第一行.</p>
<p>当有两个参数的时候.就是分页了.第一个参数是从哪行开始,第二个参数是展示多少条数据.如下面语句就是展示前20条数据</p>
<pre><code>SELECT ... FROM ... ORDER BY ... LIMIT 0, 20;
</code></pre>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://zhangbo4881820.gitee.io/myblog">brad 随风起舞</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://zhangbo4881820.gitee.io/myblog/posts/15095/">https://zhangbo4881820.gitee.io/myblog/posts/15095/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://zhangbo4881820.gitee.io/myblog" target="_blank">静待花开</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/myblog/tags/mysql/">mysql</a></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/myblog/posts/15287/" title="mysqlCookBook02"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">mysqlCookBook02</div></div></a></div><div class="next-post pull-right"><a href="/myblog/posts/27749/" title="数据结构(JAVA)第五天(search)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">数据结构(JAVA)第五天(search)</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/myblog/posts/17440/" title="mysql-index"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-14</div><div class="title">mysql-index</div></div></a></div><div><a href="/myblog/posts/15287/" title="mysqlCookBook02"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-26</div><div class="title">mysqlCookBook02</div></div></a></div><div><a href="/myblog/posts/64374/" title="mysqlCookBook03"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-27</div><div class="title">mysqlCookBook03</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/myblog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">brad 随风起舞</div><div class="author-info__description">有些事情需要一辈子的沉淀</div></div><div class="card-info-data site-data is-center"><a href="/myblog/archives/"><div class="headline">文章</div><div class="length-num">57</div></a><a href="/myblog/tags/"><div class="headline">标签</div><div class="length-num">20</div></a><a href="/myblog/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><a id="card-info-btn" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/xxxxx" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:xxxxxx@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%AE%BE%E7%BD%AEmysql%E7%94%A8%E6%88%B7%E8%B4%A6%E6%88%B7"><span class="toc-number">1.</span> <span class="toc-text">设置mysql用户账户</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8C%E6%95%B0%E6%8D%AE%E8%A1%A8"><span class="toc-number">2.</span> <span class="toc-text">创建数据库和数据表</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%85%B6%E4%BB%96mysql%E7%A8%8B%E5%BA%8F"><span class="toc-number">3.</span> <span class="toc-text">其他mysql程序</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%90%84%E7%A7%8DMySQL%E7%A8%8B%E5%BA%8F%E7%BB%84"><span class="toc-number">4.</span> <span class="toc-text">各种MySQL程序组</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%90%84%E7%A7%8D%E5%91%BD%E4%BB%A4%E8%AF%AD%E5%8F%A5"><span class="toc-number">5.</span> <span class="toc-text">各种命令语句</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%94%A8%E6%88%B7%E8%87%AA%E5%AE%9A%E4%B9%89%E5%8F%98%E9%87%8F"><span class="toc-number">5.1.</span> <span class="toc-text">用户自定义变量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%97%B6%E9%97%B4%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0DATE-FORMAT-date-format"><span class="toc-number">5.2.</span> <span class="toc-text">时间格式化函数DATE_FORMAT(date,format)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%A9%BA%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="toc-number">5.3.</span> <span class="toc-text">空表达式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E8%A7%86%E5%9B%BE"><span class="toc-number">5.4.</span> <span class="toc-text">使用视图</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%9A%E4%B8%AA%E8%A1%A8%E4%B8%AD%E6%9F%A5%E8%AF%A2%E6%95%B0%E6%8D%AE"><span class="toc-number">5.5.</span> <span class="toc-text">多个表中查询数据</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#LIMIT%E4%BD%BF%E7%94%A8"><span class="toc-number">5.6.</span> <span class="toc-text">LIMIT使用</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/15695/" title="jenkins（1）">jenkins（1）</a><time datetime="2023-09-14T02:17:44.000Z" title="发表于 2023-09-14 10:17:44">2023-09-14</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/22012/" title="wsl的Ubuntu子系统（1）">wsl的Ubuntu子系统（1）</a><time datetime="2023-09-13T08:42:19.000Z" title="发表于 2023-09-13 16:42:19">2023-09-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/30302/" title="effective-java-(接口优于抽象类)">effective-java-(接口优于抽象类)</a><time datetime="2023-09-12T08:12:48.000Z" title="发表于 2023-09-12 16:12:48">2023-09-12</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/9473/" title="effective-java(创建和销毁对象--组合的形式优于继承)">effective-java(创建和销毁对象--组合的形式优于继承)</a><time datetime="2023-09-11T08:23:19.000Z" title="发表于 2023-09-11 16:23:19">2023-09-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/16107/" title="Hello World">Hello World</a><time datetime="2023-09-07T09:44:01.910Z" title="发表于 2023-09-07 17:44:01">2023-09-07</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By brad 随风起舞</div><div class="framework-info"><span>框架 </span><a href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/myblog/js/utils.js"></script><script src="/myblog/js/main.js"></script><script src="/myblog/js/fancybox.umd.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div class="no-result" id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/myblog/js/search/local-search.js"></script></div></div></body></html>